<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>video_list</title>
    <!--    载入bootstrap的css模板-->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
    <!--    导入bootstrap的js插件必须先导入，jquery-->
    <script src="../bootstrap/js/jquery/jquery.min.js"></script>
    <!--    导入bootstrap的js插件-->
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/sweetalert/2.1.2/sweetalert.min.js" type="text/javascript"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-static-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false"
                    aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">在线视频后台管理</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <!--                <li><a href="#">设置</a></li>-->
                <li><a href="#">退出</a></li>
            </ul>
            <!--            <form class="navbar-form navbar-right">-->
            <!--                <input type="text" class="form-control" placeholder="搜索">-->
            <!--            </form>-->
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="./index.html">总览 <span class="sr-only">(current)</span></a></li>
                <li class="active"><a href="./video_list.html">视频管理</a></li>
                <li><a href="./order_list.html">订单管理</a></li>
                <li><a href="./user_list.html">用户管理</a></li>
            </ul>
        </div>
        <div class="col-sm-9 main">
            <h2 class="sub-header">视频列表</h2>
            <!-- 绑定模态框按钮 -->
            <button class="btn btn-primary" data-toggle="modal" data-target="#videoModal" id="insertBtn">添加视频</button>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>视频ID</th>
                        <th>视频名称</th>
                        <th>视频作者</th>
                        <th>视频类型</th>
                        <th>视频描述</th>
                        <th>视频审核</th>
                        <th>视频可否观看</th>
                        <th>视频上传时间</th>
                        <th>视频点赞数</th>
                        <th>视频收藏数</th>
                        <th>视频路径</th>
                        <th>视频封面</th>
                        <th>视频访问量</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tb1">

                    </tbody>
                </table>
            </div>
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li id="pageStart"><a href="#">首页</a></li>
                    <li id="pagePrevious">
                        <a href="#" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    <li id="page"></li>
                    <li id="pageNext">
                        <a href="#" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                    <li id="pageEnd"><a href="#">尾页</a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">视频添加</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-1"></div>
                    <div class="col-md-10">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <input type="hidden" name="action" id="action" value="insert">
                                <input type="hidden" name="id" id="id" value="">
                                <label for="videoId" class="col-sm-3 control-label">视频名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoId" placeholder="视频名称 不能以数字开头或空">
                                    <p id="tips"></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoUser" class="col-sm-3 control-label">视频作者</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoUser" placeholder="视频作者 不能是0">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoType" class="col-sm-3 control-label">视频类型</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoType" placeholder="视频类型 不能是0">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoDescribe" class="col-sm-3 control-label">视频描述</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" id="videoDescribe" placeholder="视频描述"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoExamine" class="col-sm-3 control-label">视频审核</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoExamine" placeholder="视频审核 只能是0或1">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoIsviewable" class="col-sm-3 control-label">视频可否观看</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoIsviewable"
                                           placeholder="视频可否观看 只能是0或1">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoUploadDate" class="col-sm-3 control-label">视频上传时间</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoUploadDate" placeholder="视频上传时间"
                                           readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoStarNum" class="col-sm-3 control-label">视频点赞数</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoStarNum"
                                           placeholder="视频点赞数 只能是阿拉伯数字">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoCollectionNum" class="col-sm-3 control-label">视频收藏数</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="videoCollectionNum"
                                           placeholder="视频收藏数 只能是阿拉伯数字">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoUrl" class="col-sm-3 control-label">视频路径</label>
                                <div class="col-sm-9">
                                    <input type="file" class="form-control" id="videoUrl" onchange="upVideo()">
                                    <input type="hidden" name="filename">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="videoImg" class="col-sm-3 control-label">视频封面</label>
                                <div class="col-sm-9">
                                    <input type="file" class="form-control" id="videoImg" onchange="upVideo()">
                                    <input type="hidden" name="filename">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="visit" class="col-sm-3 control-label">视频访问量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="visit" placeholder="视频访问量 只能是阿拉伯数字">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="col-md-1"></div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="close">关闭</button>
                <button type="button" class="btn btn-primary" id="btn3">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    /**
     * 上传视频
     **/
    function upVideo() {
        var video = $("#videoUrl")[0].files[0];
        console.log(video)
        var myForm = new FormData();
        myForm.append("img", video);
        $.ajax({
            type: "post",
            url: "./videoLoad.do",
            data: myForm,
            processData: false,
            contentType: false,
            dataType: "text",
            success: function (data) {
                // $('input[name="filename"]').val(data)
                // $("#show").attr("src","/fantasy/Video/"+data)
            },
        })
    }

    /**
     * 获取当前时间
     **/
    function getTime() {
        var nowDate = new Date();
        var year = nowDate.getFullYear();
        var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
        var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
        var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
        var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
        var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
        var date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
        $("#videoUploadDate").val(date)
    }

    /**
     * 修改视频信息
     */
    function upData(data) {
        $("#myModalLabel").text("视频修改");
        // clearInterval(interval);
        interval = setInterval('getTime()', 1000);
        var id = $(data).parent().parent().children("td").eq(0).text().trim();
        var name = $(data).parent().parent().children("td").eq(1).text().trim();
        var videoUser = $(data).parent().parent().children("td").eq(2).text().trim();
        var videoType = $(data).parent().parent().children("td").eq(3).text().trim();
        var videoDescribe = $(data).parent().parent().children("td").eq(4).text().trim();
        var videoExamine = $(data).parent().parent().children("td").eq(5).text().trim();
        var videoIsviewable = $(data).parent().parent().children("td").eq(6).text().trim();
        var videoUploadDate = $(data).parent().parent().children("td").eq(7).text().trim();
        var videoStarNum = $(data).parent().parent().children("td").eq(8).text().trim();
        var videoCollectionNum = $(data).parent().parent().children("td").eq(9).text().trim();
        var videoUrl = $(data).parent().parent().children("td").eq(10).text().trim();
        var videoImg = $(data).parent().parent().children("td").eq(11).text().trim();
        var visit = $(data).parent().parent().children("td").eq(12).text().trim();
        /**
         *  正则表达式
         **/
        var vname = /^[\u4e00-\u9fa5A-Za-z]+([0-9]*)$/;
        var num1 = /^[^0][0-9]*$/;
        var num2 = /^[0-1]+$/;
        var num3 = /^[0-9]+$/;
        $("#videoId").blur(function () {
            if ($("#videoId").val() !==name) {
                if (!vname.test($("#videoId").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoId").css("box-shadow", '0  0 2px 2px red')
                    $("#videoId").css("color", 'red')
                    swal({
                        title: "您输入的视频名称有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoId").css("box-shadow", '0  0 2px 2px white')
                    $("#videoId").css("color", 'black')
                }
            }
        })
        $("#videoUser").blur(function () {
            if ($("#videoUser").val() !== videoUser) {
                if (!num1.test($("#videoUser").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoUser").css("box-shadow", '0  0 2px 2px red')
                    $("#videoUser").css("color", 'red')
                    swal({
                        title: "您输入的作者ID有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoUser").css("box-shadow", '0  0 2px 2px white')
                    $("#videoUser").css("color", 'black')
                }
            }
        })
        $("#videoType").blur(function () {
            if ($("#videoType").val() !== videoType) {
                if (!num1.test($("#videoType").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoType").css("box-shadow", '0  0 2px 2px red')
                    $("#videoType").css("color", 'red')
                    swal({
                        title: "您输入的类型ID有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoType").css("box-shadow", '0  0 2px 2px white')
                    $("#videoType").css("color", 'black')
                }
            }
        })
        $("#videoExamine").blur(function () {
            if ($("#videoExamine").val() !== videoExamine) {
                if (!num2.test($("#videoExamine").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoExamine").css("box-shadow", '0  0 2px 2px red')
                    $("#videoExamine").css("color", 'red')
                    swal({
                        title: "您输入的审核信息有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoExamine").css("box-shadow", '0  0 2px 2px white')
                    $("#videoExamine").css("color", 'black')
                }
            }
        })
        $("#videoIsviewable").blur(function () {
            if ($("#videoIsviewable").val() !== videoIsviewable) {
                if (!num2.test($("#videoIsviewable").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoIsviewable").css("box-shadow", '0  0 2px 2px red')
                    $("#videoIsviewable").css("color", 'red')
                    swal({
                        title: "您输入的是否观看信息有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoIsviewable").css("box-shadow", '0  0 2px 2px white')
                    $("#videoIsviewable").css("color", 'black')
                }
            }
        })
        $("#videoStarNum").blur(function () {
            if ($("#videoStarNum").val() !== videoStarNum ) {
                if (!num3.test($("#videoStarNum").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoStarNum").css("box-shadow", '0  0 2px 2px red')
                    $("#videoStarNum").css("color", 'red')
                    swal({
                        title: "您输入的点赞数有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoStarNum").css("box-shadow", '0  0 2px 2px white')
                    $("#videoStarNum").css("color", 'black')
                }
            }
        })
        $("#videoCollectionNum").blur(function () {
            if ($("#videoCollectionNum").val() !== videoCollectionNum) {
                if (!num3.test($("#videoCollectionNum").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#videoCollectionNum").css("box-shadow", '0  0 2px 2px red')
                    $("#videoCollectionNum").css("color", 'red')
                    swal({
                        title: "您输入的收藏数有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#videoCollectionNum").css("box-shadow", '0  0 2px 2px white')
                    $("#videoCollectionNum").css("color", 'black')
                }
            }
        })
        $("#visit").blur(function () {
            if ($("#visit").val() !== visit) {
                if (!num3.test($("#visit").val())) {
                    // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                    $("#visit").css("box-shadow", '0  0 2px 2px red')
                    $("#visit").css("color", 'red')
                    swal({
                        title: "您输入的访问量有误，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    $("#visit").css("box-shadow", '0  0 2px 2px white')
                    $("#visit").css("color", 'black')
                }
            }
        })


        // console.log(id)
        // console.log(name)
        // console.log(videoUser)
        // console.log(videoType)
        // console.log(videoDescribe)
        // console.log(videoExamine)
        // console.log(videoIsviewable)
        // console.log(videoUploadDate)
        // console.log(videoStarNum)
        // console.log(videoCollectionNum)
        // console.log(videoUrl)
        // console.log(videoImg)
        // console.log(visit)
        $("#videoId").val(name);
        $("#videoUser").val(videoUser);
        $("#videoType").val(videoType);
        $("#videoDescribe").val(videoDescribe);
        $("#videoExamine").val(videoExamine);
        $("#videoIsviewable").val(videoIsviewable);
        $("#videoUploadDate").val(videoUploadDate);
        $("#videoStarNum").val(videoStarNum);
        $("#videoCollectionNum").val(videoCollectionNum);
        $("#visit").val(visit);
        /**
         * 关闭模态框后自动刷新
         **/
        $('#videoModal').on('hide.bs.modal', function () {
            location.reload();
        });
        /**
         * 点击保存按钮
         **/
        $("#btn3").click(function () {
            if ($("#videoId").val()===""||
                $("#videoUser").val()===""||
                $("#videoType").val()===""||
                $("#videoDescribe").val()===""||
                $("#videoExamine").val()===""||
                $("#videoIsviewable").val()===""||
                $("#videoStarNum").val()===""||
                $("#videoCollectionNum").val()===""||
                $("#videoUrl").val()===""||
                $("#videoImg").val()===""||
                $("#visit").val()===""){
                swal({
                    title: "您输入的信息有误或有信息未输入，请重新输入！",
                    icon: "error",
                    button: "确定",
                })
            }else {
                $.ajax({
                    data: {
                        id: id,
                        name: $("#videoId").val(),
                        videoUser: $("#videoUser").val(),
                        videoType: $("#videoType").val(),
                        videoDescribe: $("#videoDescribe").val(),
                        videoExamine: $("#videoExamine").val(),
                        videoIsviewable: $("#videoIsviewable").val(),
                        videoUploadDate: $("#videoUploadDate").val(),
                        videoStarNum: $("#videoStarNum").val(),
                        videoCollectionNum: $("#videoCollectionNum").val(),
                        videoUrl: $("#videoUrl").val(),
                        videoImg: $("#videoImg").val(),
                        visit: $("#visit").val(),
                    },
                    type: "get",
                    url: "./video.do?action=upData",
                    success: function () {
                        window.location.reload()
                    }
                })
            }

        });

    }

    /**
     * 删除视频
     */

    function dlt(data) {
        var trim = $(data).parent().parent().children("td").eq(0).text().trim();
        console.log(trim)
        swal({
            title: "是否删除id:" + trim + "的商品",
            icon: "warning",
            // button: "确定删除",
            buttons: {
                button1: {
                    text: "取消",
                    value: false,
                },
                button2: {
                    text: "确定删除",
                    value: true,
                }
            }
        }).then(function (isOk) {
            if (isOk) {
                $.ajax({
                    url: "./video.do?action=delete",
                    data: {
                        id: trim,
                    },
                    type: "get",
                    success: function () {
                        window.location.reload()
                    }
                })
            }
        })

    }

    $(function () {
        var interval;
        /**
         * 添加视频
         */
        $("#insertBtn").click(function () {
            /**
             *  正则表达式
             **/
            var vname = /^[\u4e00-\u9fa5A-Za-z]+([0-9]*)$/;
            var num1 = /^[^0][0-9]*$/;
            var num2 = /^[0-1]+$/;
            var num3 = /^[0-9]+$/;
            $("#videoId").blur(function () {
                if ($("#videoId").val() !== "") {
                    if (!vname.test($("#videoId").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoId").css("box-shadow", '0  0 2px 2px red')
                        $("#videoId").css("color", 'red')
                        swal({
                            title: "您输入的视频名称有误,请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoId").css("box-shadow", '')
                        $("#videoId").css("color", 'black')
                    }
                }
            })
            $("#videoUser").blur(function () {
                if ($("#videoUser").val() !== "") {
                    if (!num1.test($("#videoUser").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoUser").css("box-shadow", '0  0 2px 2px red')
                        $("#videoUser").css("color", 'red')
                        swal({
                            title: "您输入的作者ID有误，请重新输入!",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoUser").css("box-shadow", '')
                        $("#videoUser").css("color", 'black')
                    }
                }
            })
            $("#videoType").blur(function () {
                if ($("#videoType").val() !== "") {
                    if (!num1.test($("#videoType").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoType").css("box-shadow", '0  0 2px 2px red')
                        $("#videoType").css("color", 'red')
                        swal({
                            title: "您输入的类型ID有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoType").css("box-shadow", '')
                        $("#videoType").css("color", 'black')
                    }
                }
            })
            // $("#videoDescribe").blur(function () {
            //     if ($("#videoDescribe").val() !== "") {
            //         if (!vname.test($("#videoDescribe").val())) {
            //             // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
            //             $("#videoDescribe").css("box-shadow", '0  0 2px 2px red')
            //             $("#videoDescribe").css("color", 'red')
            //             alert("视频描述格式有误,请重新输入！")
            //         }
            //     }
            // })
            $("#videoExamine").blur(function () {
                if ($("#videoExamine").val() !== "") {
                    if (!num2.test($("#videoExamine").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoExamine").css("box-shadow", '0  0 2px 2px red')
                        $("#videoExamine").css("color", 'red')
                        swal({
                            title: "您输入的审核信息有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoExamine").css("box-shadow", '')
                        $("#videoExamine").css("color", 'black')
                    }
                }
            })
            $("#videoIsviewable").blur(function () {
                if ($("#videoIsviewable").val() !== "") {
                    if (!num2.test($("#videoIsviewable").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoIsviewable").css("box-shadow", '0  0 2px 2px red')
                        $("#videoIsviewable").css("color", 'red')
                        swal({
                            title: "您输入的是否观看信息有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoIsviewable").css("box-shadow", '')
                        $("#videoIsviewable").css("color", 'black')
                    }
                }
            })
            $("#videoStarNum").blur(function () {
                if ($("#videoStarNum").val() !== "") {
                    if (!num3.test($("#videoStarNum").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoStarNum").css("box-shadow", '0  0 2px 2px red')
                        $("#videoStarNum").css("color", 'red')
                        swal({
                            title: "您输入的点赞数有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoStarNum").css("box-shadow", '')
                        $("#videoStarNum").css("color", 'black')
                    }
                }
            })
            $("#videoCollectionNum").blur(function () {
                if ($("#videoCollectionNum").val() !== "") {
                    if (!num3.test($("#videoCollectionNum").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#videoCollectionNum").css("box-shadow", '0  0 2px 2px red')
                        $("#vvideoCollectionNum").css("color", 'red')
                        swal({
                            title: "您输入的收藏数有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#videoCollectionNum").css("box-shadow", '')
                        $("#vvideoCollectionNum").css("color", 'black')
                    }
                }
            })
            $("#visit").blur(function () {
                if ($("#visit").val() !== "") {
                    if (!num3.test($("#visit").val())) {
                        // $("#tips").html("<h4 style=\"color: red\">格式有误,请重新输入！</h4>");
                        $("#visit").css("box-shadow", '0  0 2px 2px red')
                        $("#visit").css("color", 'red')
                        swal({
                            title: "您输入的访问量有误，请重新输入！",
                            icon: "error",
                            button: "确定",
                        })
                    }else {
                        $("#visit").css("box-shadow", '')
                        $("#visit").css("color", 'black')
                    }
                }
            })


            /**
             * 计时器
             **/
            interval = setInterval('getTime()', 1000);
            $("#videoId").val("");
            $("#videoUser").val("");
            $("#videoType").val("");
            $("#videoDescribe").val("");
            $("#videoExamine").val("");
            $("#videoIsviewable").val("");
            $("#videoStarNum").val("");
            $("#videoCollectionNum").val("");
            $("#videoUrl").val("");
            $("#videoImg").val("");
            $("#visit").val("");
            /**
             * 关闭模态框后自动刷新
             **/
            $('#videoModal').on('hide.bs.modal', function () {
                location.reload();
            });
            /**
             *点击保存按钮
             **/
            $("#btn3").click(function () {
                if ($("#videoId").val()===""||
                    $("#videoUser").val()===""||
                    $("#videoType").val()===""||
                    $("#videoDescribe").val()===""||
                    $("#videoExamine").val()===""||
                    $("#videoIsviewable").val()===""||
                    $("#videoStarNum").val()===""||
                    $("#videoCollectionNum").val()===""||
                    $("#videoUrl").val()===""||
                    $("#videoImg").val()===""||
                    $("#visit").val()===""){
                    swal({
                        title: "您输入的信息有误或有信息未输入，请重新输入！",
                        icon: "error",
                        button: "确定",
                    })
                }else {
                    swal({
                        title: "是否添加视频",
                        icon: "warning",
                        buttons: {
                            button1: {
                                text: "取消",
                                value: false,
                            },
                            button2: {
                                text: "确定添加",
                                value: true,
                            }
                        }
                    }).then(function (isOk) {
                        if (isOk) {
                            $.ajax({
                                url: "./video.do?action=insert",
                                data: {
                                    videoId: $("#videoId").val(),
                                    videoUser: $("#videoUser").val(),
                                    videoType: $("#videoType").val(),
                                    videoDescribe: $("#videoDescribe").val(),
                                    videoExamine: $("#videoExamine").val(),
                                    videoIsviewable: $("#videoIsviewable").val(),
                                    videoUploadDate: $("#videoUploadDate").val(),
                                    videoStarNum: $("#videoStarNum").val(),
                                    videoCollectionNum: $("#videoCollectionNum").val(),
                                    videoUrl: $("#videoUrl").val(),
                                    videoImg: $("#videoImg").val(),
                                    visit: $("#visit").val()
                                },
                                type: "get",
                                success: function () {
                                    window.location.reload();
                                }
                            });
                        }
                    })
                }
            })
        })
        ;

        /**
         * 查看视频信息
         **/

        $.ajax({

            url: "./video.do?action=adminPage",
            type: "get",
            success: function (data) {
                var jsonObj = JSON.parse(data);
                for (var i = 0; i < (jsonObj.items).length; i++) {
                    var video = jsonObj.items[i];
                    $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                        "                            <button class=\"btn btn-info btn-video-upData\" onclick='upData(this)' data-toggle=\"modal\" data-target=\"#videoModal\">修改</button>\n" +
                        "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                        "                        </td></tr>");
                }
                /**
                 * 页数
                 * */
                var beginPageNo = 0;
                var endPageNo = 0;
                if (jsonObj.pageTotal <= 5) {
                    beginPageNo = 1;
                    endPageNo = jsonObj.pageTotal;
                } else {

                    beginPageNo = jsonObj.pageNo;
                    endPageNo = jsonObj.pageTotal;


                }
                /**
                 * 分页查询(首页)
                 **/

                $("#pageStart").click(function () {
                    jsonObj.pageNo=1
                    $('#tb1').empty();
                    $("#page").empty();
                    for (var j = 1; j <=5; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        $("#" + jsonObj.pageNo+ "").css("background-color", "#EEEEEE")
                        $("#" + j + "").click(function () {
                            $("#" + beginPageNo+ "").css("background-color", "white")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {
                                    var jsonObj = JSON.parse(data);
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }

                                }
                            })
                        })
                    }
                    $.ajax({
                        url: "./video.do?action=adminPage&pageNo=" + 1 + "&pageSize=" + jsonObj.pageSize + "",
                        type: "get",
                        success: function (data) {
                            var jsonObj = JSON.parse(data);
                            for (var i = 0; i < (jsonObj.items).length; i++) {
                                var video = jsonObj.items[i];
                                $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                    "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                    "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                    "                        </td></tr>");
                            }
                        }
                    })
                });


                /**
                 * 分页查询(尾页)
                 **/
                $("#pageEnd").click(function () {
                    jsonObj.pageNo=jsonObj.pageTotal
                    $('#tb1').empty();
                    $("#page").empty();
                    for (var j = jsonObj.pageTotal-4; j <=jsonObj.pageTotal; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        $("#" + jsonObj.pageTotal + "").css("background-color", "#EEEEEE")
                        $("#" + j + "").click(function () {
                            $("#" + jsonObj.pageTotal + "").css("background-color","white")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {
                                    var jsonObj = JSON.parse(data);
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }

                                }
                            })
                        })
                    }
                    $.ajax({
                        url: "./video.do?action=adminPage&pageNo=" + jsonObj.pageTotal + "&pageSize=" + jsonObj.pageSize + "",
                        type: "get",
                        success: function (data) {
                            var jsonObj = JSON.parse(data);
                            for (var i = 0; i < (jsonObj.items).length; i++) {
                                var video = jsonObj.items[i];

                                $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                    "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                    "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                    "                        </td></tr>");
                            }
                        }
                    })
                });

                /**
                 * 分页查询(下一页)
                 **/
                $("#pageNext").click(function () {
                    $('#tb1').empty();
                    $("#page").empty();
                    /**
                     *改变页数
                     **/
                    if (jsonObj.pageTotal <= 5) {

                        beginPageNo = 1;
                        endPageNo = jsonObj.pageTotal;
                    }else {

                        if(jsonObj.pageNo === 1){
                            beginPageNo = jsonObj.pageNo+1;
                            endPageNo = beginPageNo+4;
                        }else if(jsonObj.pageNo >5&&jsonObj.pageNo <= jsonObj.pageTotal-4){
                            beginPageNo = jsonObj.pageNo;
                            endPageNo = beginPageNo+4;
                        }else if (jsonObj.pageNo>1&&jsonObj.pageNo<=5){
                            beginPageNo = jsonObj.pageNo+1;
                            endPageNo = beginPageNo+4;
                        }else if(jsonObj.pageNo === jsonObj.pageTotal){
                            beginPageNo = jsonObj.pageNo-4;
                            endPageNo = jsonObj.pageNo;
                        }
                    }

                    for (var j = beginPageNo; j <=endPageNo; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        if (beginPageNo<=jsonObj.pageTotal&&beginPageNo>=jsonObj.pageTotal-4){
                            $("#" + jsonObj.pageNo + "").css("background-color", "#EEEEEE")
                        }else {
                            $("#" + beginPageNo + "").css("background-color", "#EEEEEE")
                        }
                        $("#" + j + "").click(function () {
                            $("#" + beginPageNo + "").css("background-color", "")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {
                                    var jsonObj = JSON.parse(data);
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }

                                }
                            })
                        })
                    }
                    $.ajax({
                        url: "./video.do?action=adminPage&pageNo=" + ((jsonObj.pageNo) < jsonObj.pageTotal ? (++jsonObj.pageNo) : jsonObj.pageTotal) + "&pageSize=" + jsonObj.pageSize + "",
                        type: "get",
                        success: function (data) {
                            var jsonObj = JSON.parse(data);
                            for (var i = 0; i < (jsonObj.items).length; i++) {
                                var video = jsonObj.items[i];

                                $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                    "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                    "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                    "                        </td></tr>");
                            }
                        }
                    })
                });
                /**
                 * 分页查询(上一页)
                 **/
                $("#pagePrevious").click(function () {
                    $('#tb1').empty();
                    $("#page").empty();
                    /**
                     *改变页数
                     **/
                    if (jsonObj.pageTotal <= 5) {
                        beginPageNo = 1;
                        endPageNo = jsonObj.pageTotal;
                    }else {

                        if(jsonObj.pageNo === jsonObj.pageTotal){
                            beginPageNo = jsonObj.pageNo-4;
                            endPageNo = jsonObj.pageNo;
                        }else if(jsonObj.pageNo <= jsonObj.pageTotal-4&&jsonObj.pageNo>1){
                            beginPageNo = jsonObj.pageNo-1;
                            endPageNo = beginPageNo+4;
                        }else if(jsonObj.pageNo === 1){
                            beginPageNo = jsonObj.pageNo;
                            endPageNo = beginPageNo+4;
                        }

                    }
                    for (var j = beginPageNo; j <=endPageNo ; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        if (beginPageNo<=jsonObj.pageTotal&&beginPageNo>=jsonObj.pageTotal-4){
                            $("#" + jsonObj.pageNo + "").css("background-color", "#EEEEEE")
                        }else {
                            $("#" + beginPageNo + "").css("background-color", "#EEEEEE")
                        }
                        $("#" + j + "").click(function () {
                            $("#" + beginPageNo + "").css("background-color", "white")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {
                                    var jsonObj = JSON.parse(data);
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }

                                }
                            })
                        })
                    }
                    $.ajax({
                        url: "./video.do?action=adminPage&pageNo=" + ((jsonObj.pageNo) > 1 ? (--jsonObj.pageNo) : jsonObj.pageNo) + "&pageSize=" + jsonObj.pageSize + "",
                        type: "get",
                        success: function (data) {
                            var jsonObj = JSON.parse(data);
                            for (var i = 0; i < (jsonObj.items).length; i++) {
                                var video = jsonObj.items[i];

                                $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                    "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                    "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                    "                        </td></tr>");
                            }

                        }
                    })

                });

                /**
                 *初始页数
                 **/
                if (endPageNo > 5) {
                    for (var j = beginPageNo; j <= 5; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        /**
                         *页数
                         **/
                        $("#" + jsonObj.pageNo+ "").css("background-color", "#EEEEEE")
                        $("#" + j + "").click(function () {
                            $("#" + beginPageNo+ "").css("background-color", "white")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {
                                    var jsonObj = JSON.parse(data);
                                    console.log(jsonObj)
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }
                                }
                            })
                        });
                    }

                }else {
                    for (var j = beginPageNo; j <= endPageNo; j++) {
                        $("#page").append("<a  href=\"#\" id='" + j + "' value='./video.do?action=adminPage&pageNo=" + j + "&pageSize=" + jsonObj.pageSize + "'>" + j + "</a>");
                        /**
                         *页数
                         **/
                        $("#" + jsonObj.pageNo+ "").css("background-color", "#EEEEEE")
                        $("#" + j + "").click(function () {
                            $("#" + beginPageNo+ "").css("background-color", "white")
                            $('#tb1').empty();
                            $.ajax({
                                url: $(this).attr("value"),
                                type: "get",
                                success: function (data) {

                                    var jsonObj = JSON.parse(data);
                                    console.log(jsonObj)
                                    for (var i = 0; i < (jsonObj.items).length; i++) {
                                        var video = jsonObj.items[i];

                                        $('#tb1').append("<tr><td>" + video.id + "</td><td>" + video.name + "</td><td>" + video.userId + "</td><td>" + video.typeId + "</td><td>" + video.describe + "</td><td>" + video.examine + "</td><td>" + video.isViewable + "</td><td>" + video.uploadDate + "</td><td>" + video.starNum + "</td><td>" + video.collectionNum + "</td><td>" + video.url + "</td><td>" + video.videoImg + "</td><td>" + video.visit + "</td><td>\n" +
                                            "                            <button class=\"btn btn-info btn-video-upData\" data-toggle=\"modal\" data-target=\"#videoModal\" onclick='upData(this)'>修改</button>\n" +
                                            "                            <button class=\"btn btn-danger btn-video-delete\" onclick='dlt(this)'>删除</button>\n" +
                                            "                        </td></tr>");
                                    }
                                }
                            })
                        });
                    }
                }
            }

        });

    })
    ;
</script>
</body>
</html>